using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantSubmarineShockPhysicReactor
/// \brief  Control the physic of the shocks
[AddComponentMenu("GK/AbyssalGiant/Submarine/gkAbyssalGiantSubmarineShockPhysicReactor")]
public class gkAbyssalGiantSubmarineShockPhysicReactor : MonoBehaviour 
{
	/// The shock strength
	public float ShockStrength = 17.5f;

	/// The shock strength
	public float Friction = 5.0f;

	/// The physic component that handle the shock
	private gkPhysicComponent m_rShockPhysicComponent;
	
	/// \brief  Called just after the game begin to play
	void Start()
	{
		// Create the schock physic component
		m_rShockPhysicComponent = gameObject.AddComponent<gkPhysicComponent>();
		
		// Set the physic Component Friction
		m_rShockPhysicComponent.SetFriction(Friction);
	}
	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Listen the shock event of the owner
		GetComponent<gkEventComponent>().AddEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the shock event of the owner
		GetComponent<gkEventComponent>().RemoveEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}
	
	/// Handle the begin shock event
	void HandleShockBeginEvent(Object a_rEvent)
	{
		gkAbyssalGiantShockEvent rShockEvent;
		
		rShockEvent = a_rEvent as gkAbyssalGiantShockEvent;
		
		m_rShockPhysicComponent.SetLinearVelocity(ShockStrength * rShockEvent.GetShockDirection());
	}
}